package com.shop.mapper;

import com.github.pagehelper.Page;
import com.shop.annotation.AutoFill;
import com.shop.dto.ProductPageQueryDTO;
import com.shop.entity.Product;
import com.shop.enumeration.OperationType;
import com.shop.vo.ProductVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface ProductMapper {

    /**
     * 根据分类id查询菜品数量
     *
     * @param categoryId
     * @return
     */
    @Select("select count(id) from Product where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 插入菜品数据
     *
     * @param Product
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Product Product);

    /**
     * 菜品分页查询
     *
     * @param ProductPageQueryDTO
     * @return
     */
    Page<ProductVO> pageQuery(ProductPageQueryDTO ProductPageQueryDTO);

    /**
     * 根据主键查询菜品
     *
     * @param id
     * @return
     */
    @Select("select * from Product where id = #{id}")
    Product getById(Long id);

    /**
     * 根据主键删除菜品数据
     *
     * @param id
     */
    @Delete("delete from Product where id = #{id}")
    void deleteById(Long id);

    /**
     * 根据id动态修改菜品数据
     *
     * @param Product
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Product Product);

    /**
     * 动态条件查询菜品
     *
     * @param Product
     * @return
     */
    List<Product> list(Product Product);

    /**
     * 根据套餐id查询菜品
     * @param setmealId
     * @return
     */
    @Select("select a.* from Product a left join setmeal_Product b on a.id = b.Product_id where b.setmeal_id = #{setmealId}")
    List<Product> getBySetmealId(Long setmealId);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
